﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="GradeManage.aspx.cs" Inherits="Educational_Grade_GradeManage" %>
<script type="text/javascript">
window.addEvent('domready',function(){
    window.addFormCheckForGrade=function(){
        new FormCheck('formAddForGrade',{display:{tipsPosition:'left'},submit:false,onValidateSuccess:function(){
            MUI.showModalMessage('正在添加年级');
            new Request.JSON({url:'../Ajax/GradeManage.aspx?Action=saveAddGrade',noCache:true,onSuccess:function(result){
                MUI.hideModalMessage();
                if(result.error)
                    MUI.appendStatusMessage({'text':result.msg});
                else
                {
                    $('windowAddForGrade').retrieve('instance').close();
                    MUI.appendStatusMessage({'text':result.msg});
                    window.datagridForGrade.loadData();
                }
	        },onFailure:function(error){
		        MUI.appendStatusMessage({'text':'AJAX提交表单的过程中发生未知错误。'});
		        MUI.hideModalMessage();
            }}).post($('formAddForGrade'));
        }});   
    };
    window.showAddFormForGrade=function(){
        MUI.openContentByWindow('windowAddForGrade','添加年级',$('formContainerForGrade'),$('formAddForGrade'),400,60);
    };
    
    window.updateFormCheckForGrade=function(){
        new FormCheck('formUpdateForGrade',{display:{tipsPosition:'left'},submit:false,onValidateSuccess:function(){
            MUI.showModalMessage('正在修改年级');
            new Request.JSON({url:'../Ajax/GradeManage.aspx?Action=saveUpdateGrade',noCache:true,onSuccess:function(result){
                MUI.hideModalMessage();
                if(result.error)
                    MUI.appendStatusMessage({'text':result.msg});
                else
                {
                    $('windowUpdateForGrade').retrieve('instance').close();
                    MUI.appendStatusMessage({'text':result.msg});
                    window.datagridForGrade.loadData();
                }
	        },onFailure:function(error){
		        MUI.appendStatusMessage({'text':'AJAX提交表单的过程中发生未知错误。'});
		        MUI.hideModalMessage();
            }}).post($('formUpdateForGrade'));
        }});   
    };
    window.showUpdateFormForGrade=function(){
        var indices = window.datagridForGrade.getSelectedIndices();
        if (indices.length == 0)
	    {
		    MUI.showModalAlert('您必须至少选定一行');
		    return;
	    }
	    if (indices.length > 1)
	    {
		    MUI.showModalAlert('修改时不允许一次修改多行数据。。');
		    return;
	    }
	    var selectedData=window.datagridForGrade.getDataByRow(indices[0]);
	    var element=$('formUpdateForGrade');
	    element.getElement('input[name=gradeId]').set('value',selectedData.gradeId);
	    element.getElement('input[name=gradeName]').set('value',selectedData.gradeName);
        MUI.openContentByWindow('windowUpdateForGrade','修改年级',$('formContainerForGrade'),$('formUpdateForGrade'),400,60);
    };
    
    window.deleteForGrade=function(){
        var indices = window.datagridForGrade.getSelectedIndices();
        if (indices.length == 0)
	    {
		    MUI.showModalAlert('您必须至少选定一行');
		    return;
	    }
	    if (indices.length > 1)
	    {
		    MUI.showModalAlert('删除时不允许一次删除多行数据。。');
		    return;
	    }
	    var selectedData=window.datagridForGrade.getDataByRow(indices[0]);
	    MUI.showConfirm('您确定要删除所选定的数据？此操作不可恢复！',function(){
	        MUI.showModalMessage('正在删除所选中的数据');
	        new Request.JSON({url:'../Ajax/GradeManage.aspx?Action=deleteGrade&gradeId='+selectedData.gradeId.toString(),noCache:true,onSuccess:function(result){
	            MUI.hideModalMessage();
                if(result.error)
                    MUI.appendStatusMessage({'text':result.msg});
                else
                {
                    MUI.appendStatusMessage({'text':result.msg});
                    window.datagridForGrade.loadData();
                }
            },onFailure:function(error){
	            MUI.appendStatusMessage({'text':'AJAX提交表单的过程中发生未知错误。'});
	            MUI.hideModalMessage();
            }}).get();
        });
    };
    
    window.loadDataForGrade=function(){
        window.datagridForGrade = new omniGrid('dataListForGrade', {
            columnModel: [
                {header: '年级ID',dataIndex: 'gradeId',dataType:'number',width:80,sortable:true},
                {header: '年级名称',dataIndex: 'gradeName',dataType:'string',width:120,sortable:true}
            ],
            buttons : [
                {name: '添加', bclass: 'add', onclick : window.showAddFormForGrade},
                {name: '修改', bclass: 'update', onclick : window.showUpdateFormForGrade},
                {name: '删除', bclass: 'delete', onclick : window.deleteForGrade}
            ],
            url:'../Ajax/GradeManage.aspx?Action=search',
            perPageOptions: [20,50,100,200,500,1000],
            perPage:20,
            height:$('dataListForGrade').getParent().getParent().getStyle('height').toInt(),
            serverSort:false,
            multipleSelection:false,
            sortHeader:true,
            pagination:true
        });
    };

    window.binddingEventForGrade=function(){
    };
    
    window.initializeForGrade=function(){
        new ZebraTable({elements:'table.tableFixed'});
        window.loadDataForGrade();
        window.binddingEventForGrade();
        window.addFormCheckForGrade();
        window.updateFormCheckForGrade();
    };
    
    window.initForGrade=function(){
        window.initializeForGrade();
    };
    
    window.initForGrade();
});
</script>
<div id="dataListForGrade"></div>
<!--隐藏的表单-->
<div id="formContainerForGrade" style="display:none;">

<!--添加表单-->
<form id="formAddForGrade">
    <table class="tableFixed" border="0" cellpadding="0" cellspacing="0" width="100%">
    <tr>
        <td class="tableLeft1">年级名称：</td>
        <td class="tableLeft2"><input class="input validate['required','length[2,20]']" name="gradeName" type="text" /></td>
    </tr>
    <tr>
        <td class="tableLeft1"></td>
        <td class="tableLeft2"><input class="submit button validate['submit']" type="button" value="提交添加" /></td>
    </tr>
</table>
</form>
<!--修改表单-->
<form id="formUpdateForGrade">
<input type="hidden" name="gradeId" />
    <table class="tableFixed" border="0" cellpadding="0" cellspacing="0" width="100%">
    <tr>
        <td class="tableLeft1">年级名称：</td>
        <td class="tableLeft2"><input class="input validate['required','length[2,20]']" name="gradeName" type="text" /></td>
    </tr>
    <tr>
        <td class="tableLeft1"></td>
        <td class="tableLeft2"><input class="submit button validate['submit']" type="button" value="提交修改" /></td>
    </tr>
</table>
</form>
</div>